package cn.kinoko.service.auth.tokenGranter;

import cn.kinoko.common.code.ErrorCodeEnum;
import cn.kinoko.common.utils.ExceptionUtil;
import cn.kinoko.common.utils.SpringHelper;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * @author kinoko
 */
public class TokenGranterBuilder {

    public static final String DEFAULT_GRANTER = "default";

    private static final Map<String, TokenGranter> GRANTER_POOL = Maps.newHashMap();

    static {
        GRANTER_POOL.put(DEFAULT_GRANTER, SpringHelper.getBean(DefaultTokenGranter.class));
    }

    /**
     * 获取TokenGranter
     *
     * @param type 类型
     * @return TokenGranter
     */
    public static TokenGranter getGranter(String type) {
        TokenGranter tokenGranter = GRANTER_POOL.get(type);
        ExceptionUtil.isNull(tokenGranter, ErrorCodeEnum.USER_ERROR_A0342);
        return tokenGranter;
    }

}
